//$('#addBooksForm').validate();

$('#addBooksForm').validate({
	
	errorPlacement: function(error, element) { },
	
	invalidHandler: function(e, validator) {
		var errors = validator.numberOfInvalids();
		if (errors) {
			var message = errors == 1
				? 'You missed 1 field. It has been highlighted below'
				: 'You missed ' + errors + ' fields.  They have been highlighted below';
			$("div.error span").html(message);
			$("div.error").show();
		} else {
			$("div.error").hide();
		}
	},
	onkeyup: false,
	/*
	submitHandler: function() {
		$("div.error").hide();
		alert("submit! use link below to go to the other step");
	},
	*/
	messages: {
		/*
		password2: {
			required: " ",
			equalTo: "Please enter the same password as above"
		},
		email: {
			required: " ",
			email: "Please enter a valid email address, example: you@yourdomain.com",
			remote: jQuery.validator.format("{0} is already taken, please enter a different address.")
		}
		*/
		
	}
});



$('#addBooksForm').submit(function(){
	
	requestPost($(this).attr('action'), $(this).serialize(), function(out){
		
		alert(out.msg);
		
		if(out.status){
			
			$('#addBooksForm #Purchdate').val('');
			$('#addBooksForm #accno').val('');
			$('#addBooksForm #author').val('');
			$('#addBooksForm #tittle').val('');
			$('#addBooksForm #pub').val('');
			$('#addBooksForm #isbn').val('');
			$('#addBooksForm #subj').val('');
			$('#addBooksForm #clsno').val('');
			$('#addBooksForm #edition').val('');
			$('#addBooksForm #status').val('');
			$('#addBooksForm #year').val('');
			$('#addBooksForm #pages').val('');
			$('#addBooksForm #cost').val('');
			$('#addBooksForm #volume').val('');
			$('#addBooksForm #booksrc').val('');
			$('#addBooksForm #billno').val('');
			$('#addBooksForm #addinfo').val('');
			
		}
		
	}, 'json');
	
	return false;
});

